package com.jc;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @Author: HJC
 * @Date: 2025/11/3 19:22
 * @Description:
 **/
public class App {


    public static void main(String[] args) {
        String url = null;
        String user = null;
        String password = null;

        // 从类路径加载配置文件（推荐）
        try (InputStream is = App.class.getResourceAsStream("/db.properties")) {
            if (is == null) {
                System.out.println("db.properties 未在类路径中找到");
                return; // 找不到文件时直接返回，避免后续空指针
            }
            Properties pros = new Properties();
            pros.load(is);
            url = pros.getProperty("url");
            user = pros.getProperty("user");
            password = pros.getProperty("password");
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }

        // 建立数据库连接
        try {
            // 显式加载PostgreSQL驱动（可选，但老版本JDK可能需要）
            Class.forName("org.postgresql.Driver");
            Connection conn = DriverManager.getConnection(url, user, password);
            System.out.println("连接 PostgreSql 数据库成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
